package com.wst.system.util;

import java.util.Random;

public class RandomCodeGenerator {

    // 定义所有可能的字符（字母和数字）
    private static final String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

    public static String generateRandomCode(int length) {
        Random random = new Random();
        StringBuilder code = new StringBuilder();

        for (int i = 0; i < length; i++) {
            // 随机选择一个字符
            int index = random.nextInt(CHARACTERS.length());
            code.append(CHARACTERS.charAt(index));
        }

        return code.toString();
    }

    public static void main(String[] args) {
        String code = generateRandomCode(4);
        System.out.println("Generated Code: " + code);
    }
}
